package com.zjweu.hkg.Controller;

import com.zjweu.hkg.POJO.Message;
import com.zjweu.hkg.POJO.User;
import com.zjweu.hkg.Servies.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/message")
public class MessageController {

    @Autowired
    MessageService messageService;

    @PostMapping("/getHistoryMessageByFromIdAndToId")
    public List<Message> getHistoryMessageByFromIdAndToId(int fromId, int toId)
    {
        return messageService.getHistoryMessageByFromIdAndToId(fromId,toId);
    }

    /**
     * 根据用户 ID 获取与之聊天过的用户列表
     * @param userId 用户 ID
     * @return 聊天过的用户列表
     */
    @PostMapping("/getChatUsersByUserId")
    public List<User> getChatUsersByUserId(@RequestParam int userId) {
        return messageService.getChatUsersByUserId(userId);
    }
    @PostMapping("/getUnreadMsgByUserId")
    public List<Message> getUnreadMsgByUserId(@RequestParam int userId) {
        return messageService.getUnreadMsgByUserId(userId);
    }
}
